﻿using TpExtensions;
using System;
using Microsoft.Office.Interop.Excel;

namespace TpBaseObjects.Base {

    public class TimeRow {
        
        #region Members

        private Range myRow;
        
        #endregion

        #region Construtor

        public TimeRow(Range row) {
            this.myRow = row;
        }

        #endregion

        #region Properties

        public bool HaveJobSummaryForDay {
            get {
                double s1 = 0;
                Range r1 = myRow.Cells[1, "C"];
                if (r1.Value != null) {
                    Double.TryParse(Convert.ToString(r1.Value), out s1);
                }
                return s1 != 0.0;
            }
        }

        public bool IsCurrentJobRow {
            get {
                bool ret = true;
                if (this.JobDate != new DateTime(1900, 1, 1) && this.HaveJobSummaryForDay) {
                    return true;
                }
                return ret;
            }
        }

        public bool IsFirstJobRow {
            get {
                bool ret = true;
                if (this.JobDate != new DateTime(1900, 1, 1) && !this.HaveJobSummaryForDay) {
                    return true;
                }
                return ret;
            }
        }

        public DateTime JobDate {
            get {
                DateTime ret = new DateTime(1900, 1, 1);
                string jd = "";

                Range r1 = myRow.Cells[1, "K"];
                if (r1 == null) {
                    return ret;
                }
                try {
                    jd = Convert.ToString(r1.Value);
                } catch {
                    return ret;
                }
                if (jd.IsDate() == false) {
                    return ret;
                }
                ret = DateTime.Parse(jd);
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "K"];
                if (value != new DateTime(1900, 1, 1)) {
                    r1.Value = value.ToString("yyyy/MM/dd");
                } else {
                    r1.Value = "";
                }
            }
        }

        public Double JobTimeFrom {
            get {
                double s1 = 0;
                Range r1 = myRow.Cells[1, "P"];
                if (r1.Value != null) {
                    Double.TryParse(Convert.ToString(r1.Value), out s1);
                }
                return s1;
            }
            set {
                double s1 = value;
                Range r1 = myRow.Cells[1, "P"];
                r1.Value = s1;
            }
        }

        public Double JobTimeTo {
            get {
                double s1 = 0;
                Range r1 = myRow.Cells[1, "Q"];
                if (r1.Value != null) {
                    Double.TryParse(Convert.ToString(r1.Value), out s1);
                }
                return s1;
            }
            set {
                double s1 = value;
                Range r1 = myRow.Cells[1, "P"];
                r1.Value = s1;
            }
        }

        public Double JobSummaryForDay {
            get {
                double s1 = 0;
                Range r1 = myRow.Cells[1, "C"];
                if (r1.Value != null) {
                    Double.TryParse(Convert.ToString(r1.Value), out s1);
                }
                return s1;
            }
            set {
                double s1 = value;
                Range r1 = myRow.Cells[1, "C"];
                r1.Value = s1;
            }
        }

        public int RowNumber {
            get {
                Range r1 = this.myRow;
                return r1.Row;
            }
        }

        #endregion

       

    }
}
